<?php
/*
 *      Sell.php
 *      
 *      Copyright 2011 ViRak <vetalrakitin@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

require_once($_SERVER['DOCUMENT_ROOT']."/classes/interface/oswindow.php");
require_once($_SERVER['DOCUMENT_ROOT']."/classes/interface/ostable.php");

class Sell extends oswindow {
	
	public $caption = "Документ 'Продажа'";
	
	private $ednumber;
	private $eddate;
	private $edtime;
	private $cbmanager;
	private $tagoods;
	private $btsave;
	private $btsaveandlead;
	private $btcancel;
	private $btaddrow;
	private $btdelrow;
	
	function __construct($parent) {
		parent::__construct($parent);
		$this->caption = "Документ 'Продажа'";
		$this->width = 500;
		//$this->height = 200;
		$this->aligment = "center";
		
		$this->ednumber = new osedit($this->uuid);
		$this->ednumber->readonly = true;
		
		$this->eddate = new osedit($this->uuid);
		$this->eddate->value = date("d-m-Y");
		$this->eddate->readonly = true;
		
		$this->edtime = new osedit($this->uuid);
		$this->edtime->value = date("H:i:s");
		$this->edtime->readonly = true;
		
		$this->tagoods = new ostable($this->uuid);
		$this->tagoods->addheader("code", "Код");
		//$this->tagoods->header("code")->width = 50;
		
		$this->tagoods->addheader("name", "Наименование");
		//$this->tagoods->header("name")->readonly = true;
		//$this->tagoods->header("name")->width = 50;
		$this->tagoods->addheader("price", "Цена");
		//$this->tagoods->header("price")->width = 50;
		//$this->tagoods->header("price")->readonly = true;
		$this->tagoods->addheader("count", "Кол-во");
		//$this->tagoods->header("count")->width = 50;
		$this->tagoods->addheader("summ", "Сумма");
		//$this->tagoods->header("summ")->width = 50;
		//$this->tagoods->header("summ")->readonly = true;
		$this->tagoods->setevent($this->uuid, "cellonkeypress", "tagoodsoncellkeypress");
		$this->tagoods->setevent($this->uuid, "celloninput", "tagoodsoncellinput");
		
		$this->btsave = new osbutton($this->uuid);
		$this->btsave->caption = "Сохранить";
		$this->btsave->setevent($this->uuid, "onclick", "btsaveonclick");
		$this->btlead = new osbutton($this->uuid);
		$this->btlead->caption = "Провести";
		$this->btlead->setevent($this->uuid, "onclick", "btleadonclick");
		
		$this->btaddrow = new osbutton($this->uuid);
		$this->btaddrow->caption = "+";
		$this->btaddrow->setevent($this->uuid, "onclick", "btaddrowonclick");
		$this->btdelrow = new osbutton($this->uuid);
		$this->btdelrow->caption = "-";
		$this->btdelrow->setevent($this->uuid, "onclick", "btdelrowonclick");
		
		$this->append();
		
		$this->tagoods->insertitem();
		//$this->tagoods->code->setfocus();
		
	}
	
	function save() {
	}
	
	function btsaveonclick() {
		$this->save();
	}
	
	function btleadonclick() {
		$this->lead();
	}
	
	function lead() {
	}
	
	function btaddrowonclick() {
		$this->tagoods->insertitem();
		$this->tagoods->code->setfocus();
	}
	
	function btdelrowonclick() {
		$this->tagoods->deleteitem();
		//$this->tagoods->code->setfocus();
	}
	
	function tagoodsoncellkeypress($cellname, $key) {
		
		if (($cellname == "code") && ($key == 13)) {
			$this->tagoods->count->setfocus();
		}
		if (($cellname == "count") && ($key == 13)) {
			$this->tagoods->insertitem();
			$this->tagoods->code->setfocus();
		}
	}
	
	function tagoodsoncellinput($value, $position) {
		$pos = unserialize($position);
		//new osmsgbox($pos[1]);
/*
		if ($cellname == "count") {
			if ($this->tagoods->price->value) {
				$this->tagoods->summ->value = $this->tagoods->price->value*$this->tagoods->count->value;
			}
		}
		if ($cellname == "code") {
			$list = $_SESSION["components"]["CurrentUser"]->dbconnect->get_table("sprgoods",array("code" => $value));
			if (array_key_exists(0,$list)) {
				$this->tagoods->name->value = $list[0]["name"];
				$this->tagoods->price->value = "45";
				$this->tagoods->count->value = $this->tagoods->count->value?$this->tagoods->count->value:"1";
				$this->tagoods->summ->value = $this->tagoods->price->value*$this->tagoods->count->value;
			} else {
				$this->tagoods->name->value = "";
				$this->tagoods->price->value = "";
				$this->tagoods->count->value = "";
				$this->tagoods->summ->value = "";
			}
		}
*/
	}
	
	function get() {
		$ret = $this->btsave->get();
		$ret .= $this->btlead->get();
		//і$ret .= "<input type='button' value='but' onclick='document.getElementById(\"code\").focus();'>";
		$ret .= "<table align=center><tr>";
		$ret .= "<td>Номер:</td>";
		$ret .= "<td>".$this->ednumber->get()."</td>";
		$ret .= "</tr><tr>";
		$ret .= "<td>Дата:</td>";
		$ret .= "<td>".$this->eddate->get()."</td>";
		$ret .= "</tr><tr>";
		$ret .= "<td>Время:</td>";
		$ret .= "<td>".$this->edtime->get()."</td>";
		$ret .= "</tr></table>";
		//$ret .= "<pre>".print_r($this->edit1,1)."</pre>";
		$ret .= "<div align='center'>";
		$ret .= $this->btaddrow->get();
		$ret .= $this->btdelrow->get();
		$ret .= $this->tagoods->get();
		//$ret .= $this->btlogin->get();
		//$ret .= $this->btreset->get();
		$ret .= "</div>";
/*
		$ret .= "<progress value='100' max='500'>20%</progress>";
		$ret .= "<menu>";
		$ret .= "<command onclick='alert('Первая команда)' label='Первая команда'/>";
		$ret .= "<command onclick='alert('Вторая команда)' label='Вторая команда'/>";
		$ret .= "</menu>";
*/

		return parent::get($ret);
	}
}
?>
